package com.zdpx.pxframework.auth.api.api;

import com.zdpx.pxframework.core.constant.SecurityConstant;
import com.zdpx.pxframework.core.constant.ServiceNameConstant;
import com.zdpx.pxframework.core.pojo.LoginUser;
import com.zdpx.pxframework.core.vo.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestHeader;

/**
 * Token远程调用
 *
 * @Description:
 * @Author: Cheng XiaoXiao
 * @Date: 2022/5/31 17:11
 */
@FeignClient(value = ServiceNameConstant.AUTH_SERVICE, url = "${px.open-feign.auth-url}")
public interface RemoteTokenService {

    /**
     * 根据token获取用户信息
     *
     * @param token  token
     * @param source 来源信息
     * @return 用户信息
     */
    @GetMapping("/token/login-user")
    Result<LoginUser> getLoginUserByToken(@RequestHeader(SecurityConstant.AUTHORIZATION) String token, @RequestHeader(SecurityConstant.FROM_SOURCE) String source);

    /**
     * 删除用户token
     *
     * @param token  token
     * @param source 来源信息
     * @return 删除结果
     */
    @DeleteMapping("/token")
    Result<Boolean> deleteToken(@RequestHeader(SecurityConstant.AUTHORIZATION) String token, @RequestHeader(SecurityConstant.FROM_SOURCE) String source);

    /**
     * 刷新token的过期时间
     *
     * @param token  token
     * @param source 来源信息
     * @return 刷新结果信息
     */
    @PutMapping("/token")
    Result<Boolean> refreshToken(@RequestHeader(SecurityConstant.AUTHORIZATION) String token, @RequestHeader(SecurityConstant.FROM_SOURCE) String source);
}
